package com.nut.lmsc.api.merchant;

import com.nut.lmsc.api.req.ClientLoginReq;
import com.nut.lmsc.api.resp.UserInfoResp;
import com.nut.lmsc.common.Holder;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.interceptor.AdminJwt;
import com.nut.lmsc.interceptor.MerchantJwt;
import com.nut.lmsc.service.MemberService;
import com.nut.lmsc.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 鉴权服务
 */
@RestController
@RequestMapping("/merchant/auth")
@Validated
@Slf4j
public class AuthController {

    @Autowired
    private MemberService memberService;

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/test")
    public Result test() {
        return Result.ok();
    }

    @PostMapping("login")
    public Result login(@RequestBody ClientLoginReq req) {
        return memberService.merchantLogin(req);
    }

    @GetMapping(value = "info")
    public Result<UserInfoResp> getUserInfo() {
        MerchantJwt merchantJwt = Holder.MERCHANT_JWT_THREAD_LOCAL.get();
        return sysUserService.getUserInfo(null, merchantJwt.getMobile());
    }

}
